
<?php

$hostname_CrossFit = "localhost";
$database_CrossFit = "quadnips_CF26AppsDev";
$username_CrossFit = "quadnips_26";
$password_CrossFit = "fearless";
$CrossFit = mysql_pconnect($hostname_CrossFit, $username_CrossFit, $password_CrossFit) or trigger_error(mysql_error(),E_USER_ERROR); 

echo "Okay 1";
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
echo "Okay 2";
$colname_Recordset1 = "-1";
if (isset($_POST['Email'])) {
  $colname_Recordset1 = $_POST['Email'];
}
mysql_select_db($database_Attendance, $Attendance);
$query_Recordset1 = sprintf("SELECT Email FROM members WHERE Email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $Attendance) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
echo "Okay 3";
$colname_CheckUsernam = "-1";
if (isset($_POST['Email'])) {
  $colname_CheckUsernam = $_POST['Email'];
}
mysql_select_db($database_Attendance, $Attendance);
$query_CheckUsernam = sprintf("SELECT Username FROM Login WHERE Username = %s", GetSQLValueString($colname_CheckUsernam, "text"));
$CheckUsernam = mysql_query($query_CheckUsernam, $Attendance) or die(mysql_error());
$row_CheckUsernam = mysql_fetch_assoc($CheckUsernam);
$totalRows_CheckUsernam = mysql_num_rows($CheckUsernam);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
echo "Okay 4";
if($totalRows_CheckUsernam > 0 ) { //check if there is already an entry for that username
 echo "";
} else {

echo "Okay 5";
$activationKey =  mt_rand();

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO Login (Username, Password, Active) VALUES (%s, SHA1(%s), '$activationKey')",
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['Password'], "text"),
                       GetSQLValueString($_POST['Active'], "int"));


  mysql_select_db($database_Attendance, $Attendance);
  $Result1 = mysql_query($insertSQL, $Attendance) or die(mysql_error());

##Send activation Email to Owner
echo "Okay 6";
$to      = "ryan@crossfit26.com";

$subject = "CrossFit 26 Member Registration";

$message = $_POST['Email'] . " has registered to access their member profile at http://members.crossfit26.com.";

$headers = 'From: ryan@crossfit26.com' . "\r\n";

    

mail($to, $subject, $message, $headers);

##Send activation Email to User

$to      = $_POST['Email'];

$subject = "CrossFit 26 Member Registration";

$message = "Welcome to the CrossFit 26 Member site, Let's get it!\r\rYou need to complete registration to access your profile at 26. You can complete registration by clicking the following link:\rhttp://development.crossfit26.com/app/confirmregistration.php?code=$activationKey\r\rIf this is an error, please contact ryan@crossfit26.com.\r\rRegards, the CrossFit 26 Team";

$headers = 'From: ryan@crossfit26.com' . "\r\n";

    

mail($to, $subject, $message, $headers);

  $insertGoTo = "http://development.crossfit26.com/app/";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
}
?>
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Log Out</title>
</head>

<body>
<center><img src="ajax-loader.gif" width="32" height="32" style="margin-top:150px;"><p>Processing...</p>

<p>
<font color="red"><?php if($totalRows_CheckUsernam > 0 ) { //check if there is already an entry for that username
 echo " You have already registered. Please reset your password.";
} ?></font>
</p>
</center>

<script type="text/javascript">
<!--
window.location = "http://development.crossfit26.com/app/attendance/"
//-->
</script>
</body>
</html>
